//暴露mixins对象

import {generateUUID, ifNullMergeFromObject, mergeFromObject, resetSksTableBefore} from "./core";

export const sksPrintDialogFormMixin = {
    data(){
        return {

            allLoading: false,

            showDialog: false,

            mainDialogInfo:{
                //是否启用直接打印
                directPrint: false,
                //打印之后是否关闭dialog
                printAfterClose: false,

                uid: undefined,
                //true是否已加载完成
                title: undefined,
                width: undefined,
                showQueryForm: undefined,

                readonly: false,

                //直接使用默认的即可,同一页面放两,两个组件都不同
                sourceDomId: 'sourceBom'+generateUUID(),
                //ID需要随机生成,不然如果出现不同页面调用该组件,会出现id重复导致打印内容不一致
                printDomId: 'printDiv'+generateUUID(),
            },
            defaultMainDialogInfo:{
                //是否启用直接打印
                directPrint: false,
                //打印之后是否关闭dialog
                printAfterClose: false,
                //对话框ID
                uid:undefined,
                title: '打印预览',
                width: '500px',
                showQueryForm: false,

                //不可编辑
                readonly: false,
                //编辑数据对话框使用
                //推荐返回数据格式
            },
            form:{},
            defaultForm:{},
            defaultFormNotNull:{ },

            title: '标题',

            //字典数据都放这里
            dictDataMap: new Map(),
            dictDataMapLoading: false,
            //用于选择关联表的信息,自己在页面中重新定义
            //该类中注释掉,否则会出现 undefined
            // sksSelectMap: {},

            mainTable: {
                queryParams:{
                    sksParams:{},
                    sksParamsLabel:{},
                    pageSize: 999,
                    pageNum: 1,
                },
                list:[],
                loading: false,
            },

            rules:{
            },
        }
    },
    beforeCreate(){
        // console.log("混入的beforeCreated");

    },
    created() {
        console.log("sksDialogForm.created");
        // console.log("sks-form.created.this",this)
        // console.log("sks-form.created.mainDialogInfo",this.mainDialogInfo)
        // console.log("sks-form.created.defaultMainDialogInfo",this.defaultMainDialogInfo)
        mergeFromObject(this.mainDialogInfo,this.defaultMainDialogInfo,this.initMainDialogInfo())
        // console.log("sks-form.created")
        this.sksFormInit();
    },
    mounted() {
        // console.log("sks-form.mounted")
        this.sksFormInit();
    },
    methods: {
        /**
         * 初始化 mainDialogInfo 的一些值
         * @return {}  例如: {title: '新建'} 显示工具栏的搜索放大镜
         */
        initMainDialogInfo(){
            return {}
        },
        /**
         * 需要获取的字典
         * @return []
         [
         {
                        prop: 'processStatus',
                        dictType: 'status',
                       //字典的数据类型,如果为 Number 会将字典数据转换为数字类型
                        dictValueType: 'Number'
                      }
         ]
         */
        initDictTypeConf(){
            return []
        },
        show({form,dialogInfo}={}){
            resetSksTableBefore(this.mainTable)
            // console.log("sks.show.111")
            mergeFromObject(this.mainDialogInfo,this.defaultMainDialogInfo,this.initMainDialogInfo(),dialogInfo,{
                // sourceDomId: 'sourceBom002'+generateUUIDS4(),
                // canvasDomId: 'canvasRef002'+generateUUIDS4(),
                // //ID需要随机生成,不然如果出现不同页面调用该组件,会出现id重复导致打印内容不一致
                // printDomId: 'printDiv002'+generateUUIDS4(),
            })
            this.showDialog=true
            this.resetMainForm(form)
        },
        sksFormInit({form}={}){
            this.resetMainForm(form)
        },
        resetMainForm(data){
            let form=mergeFromObject({},this.defaultForm,data)
            ifNullMergeFromObject(form,this.defaultFormNotNull)
            form=this.resetMainFormBefore(form)
            this.form= form
            this.resetForm('form')
            // console.log("sks-form.this.form=",this.form)
        },
        //全局只读
        globalReadonly(rowIn,fieldName){
            if (this.mainDialogInfo.readonly) {
                return true;
            }
            let row=rowIn!==undefined?rowIn:this.form
            if(row.status!=undefined&&row.status==1){
                return true;
            }
            return false;
        },
        //form 重新赋值前处理
        resetMainFormBefore(form){
           return form;
        },
        handleClickPrint(){
            this.handleClickPrintBefore()
            this.$nextTick(()=>{
                if(this.mainDialogInfo.printAfterClose){
                    this.showDialog=false
                }
            })
        },
        //进行校验前执行,子表校验等
        handleClickPrintBefore(){

        },
        //校验通过后执行
        validateSuccess(){
        },
        cancelMainDialog(){
            this.showDialog=false
        },
        closeDialog(){
            this.$emit('close')
        },
    },
}
